import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: LianBao
 * Date: 2024-02-29
 * Time: 11:00
 */

class Person {

    //private是访问权限修饰符,只能在类内访问,不能在类外访问
    private int age;
    private String name;
    private int money;
    public static String classRoom = "Java112";

    static {
        System.out.println("静态代码块!主要用于初始化静态成员变量");
    }

    {
        this.age = 10;
        this.name = "zhangSan";
        this.money = 9000;
        System.out.println("写在类当中,方法的外边的代码块叫构造代码块(实例代码块/非静态代码块)!一般用于赋值非静态的成员");
    }

    public Person(int age, String name, int money) {
        System.out.println("带参数的构造方法!");
        this.age = age;
        this.name = name;
        this.money = money;
    }

    public Person() {
        System.out.println("不带参数的构造方法!");
    }

    //因为不能直接访问private成员变量,所以提供公开的get和set方法获取成员变量
    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }


    //方法重写,快捷键:alt+insert->toString自动生成toString方法,可以打印类成员变量
    @Override
    public String toString() {
        return "Person{" +
                "年龄=" + age +
                ", 姓名='" + name + '\'' +
                ", 工资=" + money +
                '}';
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getMoney() {
        return money;
    }

    public void setMoney(int money) {
        this.money = money;
    }

}


public class Test {

    public static void main(String[] args) {
        Person peo1 = new Person();
        Person.classRoom = "112";//静态成员变量(类变量)通过类名点访问
//        System.out.println(peo1.classRoom);静态成员变量不在对象中,不能用对象点出来,

        System.out.println("执行顺序:静态代码块>实例代码块(构造代码块)执行>构造方法");
        System.out.println("如果都是实例的初始化,执行与代码先后顺序有关");
        System.out.println("静态代码块只执行一次,因为类只加载一次");
        System.out.println("有多个静态代码块时,按代码书写的顺序执行");
        System.out.println("sout(peo1)="+peo1);
    }

    public static void main1(String[] args) {
        int[] array = {1, 2, 3};
        Arrays.deepToString(args);
        Person person1 = new Person();
//        person1.setAge(10);
//        System.out.println(person1.getAge());

    }
}
